package com.freesun.shop.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 系统用户
 * </p>
 *
 * @author zf
 * @since 2019-11-13
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="SysUser对象", description="系统用户")
@ToString
public class SysUser implements Serializable {


    private static final long serialVersionUID = -6396324493636419313L;
    @TableId(value = "user_id", type = IdType.AUTO)
    private Long userId;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "密码")
    private String password;

    public void setPassword(String password) {
       // HashUtils.getHashValueWithSalt(password,"whsxt",2);
        this.password = "b53b8594f4e0ec33b5f3ed8c29c2a81b";
    }

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "手机号")
    private String mobile;

    /**
     * @TableLogic(delval = "0",value = "1")
     * 可以逻辑删除
     */

    @ApiModelProperty(value = "状态  0：禁用   1：正常")
    private Integer status;

    @ApiModelProperty(value = "创建者ID")
    private Long createUserId;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "用户所在的商城Id")
    private Long shopId;


    @ApiModelProperty(value = "前端显示的扩展角色字段")
    @TableField(exist = false)
   // @JsonSerialize(using = Object2Long.class)
   // @JsonDeserialize(using = Integer2Long.class)
    private List<Object> roleIdList=new ArrayList<>(0);

    public void setRoleIdList(List<Object> roleIdList) {
        if(null!=roleIdList&&roleIdList.size()>0){
            if(roleIdList.get(0).getClass().equals(Long.class)){
                this.roleIdList=roleIdList;
                return;
            }
            List<Object> roleLongs = new ArrayList<>(roleIdList.size());
            roleIdList.forEach(id -> roleLongs.add(Long.valueOf(id.toString())));
            this.roleIdList=roleLongs;
        }
    }
}
